#define _BUTTONS_C_

#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <util/delay.h>

#include "config.h"
#include "typedefs.h"
#include "buttons.h"
#include "TIMEBASE.H"





void buttonsBG(void){
  static unsigned int uiTimer;

  if(timer_timeover_ticks(uiTimer, 10)){

    if (PINB & (1<<PB0)){
		buttons.btn[0]++;
		if (buttons.btn[0] > 0x80) buttons.btn[0] = 0x80; // do not increment further than 0x80!
	} else buttons.btn[0] = 0;

    if (PINB & (1<<PB1)){
		buttons.btn[1]++;
		if (buttons.btn[1] > 0x80) buttons.btn[1] = 0x80;
	} else buttons.btn[1] = 0;

    if (PINB & (1<<PB2)){
		buttons.btn[2]++;
		if (buttons.btn[2] > 0x80) buttons.btn[2] = 0x80;
	} else buttons.btn[2] = 0;

    if (PINB & (1<<PB3)){
		buttons.btn[3]++;
		if (buttons.btn[3] > 0x80) buttons.btn[3] = 0x80;
	} else buttons.btn[3] = 0;

	uiTimer = timer_freeze_ticks();
  }

}




#undef _BUTTONS_C_
